package com.example._05mvcboot01.contrller;

import com.example._05mvcboot01.pojo.dto.UserRegDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Controller 注解：
 * 1.作用：标识当前类为控制器,
 * <p>
 * ResponseBody 注解：
 * 1.允许控制器方法返回值的形式返回给客户端数据
 * <p>
 * 客户端传递用户名和密码到服务端
 * GET:
 */
@Controller
public class UserController {
    @RequestMapping("/v1/users/login")
    @ResponseBody
    public String login() {
        return "恭喜你，登录成功!";
    }

//注册功能

    /**
     * 1.通过HttpServletRequest对象来接收
     */
    @RequestMapping("/v1/users/reg1")
    @ResponseBody
    public String reg1(HttpServletRequest request) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        return username + "---" + password;
    }

    @RequestMapping("/v1/users/reg2")
    @ResponseBody
    public String reg2(String username, String password) {
        return username + "@#$%" + password;

    }


    /**
     * 通过POJO接收
     */

    @RequestMapping("/v1/users/reg3")
    @ResponseBody
    public String reg3(UserRegDTO userRegDTO) {
        String username = userRegDTO.getUsername();
        String password = userRegDTO.getPassword();

        return username + "@❥(^_-)" + password;

    }


//    @RequestMapping("/v1/goods/index")
//    @ResponseBody
//    public String loginGoods(){
//        return "恭喜你，查询成功!";
//    }
}
